﻿//********************************************************************************//
//创建日期：<创建日期，2017-7-26>
//创建作者：<郭登杰>
//功能说明：来函公共控件-月度调整来函信息
//********************************************************************************//
using BLL.Access;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL;
using DevExpress.Web;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHXX_YDTZ : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        /// 来函流程
        /// </summary>
        public eLaiHanLCBH LaiHanLC { get; set; }
                
        /// <summary>
        /// 记录站点
        /// </summary>
        public string ZhanDianBH
        {
            get
            {
                return Convert.ToString(ViewState["ZhanDianBH"]);
            }
            set
            {
                ViewState["ZhanDianBH"] = value;
            }
        }

        /// <summary>
        /// 记录管理块
        /// </summary>
        public string GuanLiKBH
        {
            get
            {
                return Convert.ToString(ViewState["GuanLiKBH"]);
            }
            set
            {
                ViewState["GuanLiKBH"] = value;
            }
        }

        #endregion

        #region 变量

        BLL.SqlHelper sqlHelper = new BLL.SqlHelper();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }            
        }   

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            //获取合同号
           
            //e.Result = e.Parameter + "|0|" + hetongh;
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
           
        }
               
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
                return;
            }
            else
            {
                this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
            }
            txtXingZhengXKSLBH.Text = laihanxx.S_XUKEBH;
            txtTongYiSPBH.Text = laihanxx.S_TONGYIBM;
            //DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", lh.S_LAIHANBH, 2), "", null);
            //if (lcxx != null && lcxx.Rows.Count > 0)
            //{
            //    txtShouLiRQ.Text = Convert.ToDateTime(lcxx.Rows[0]["D_StartDate"]).ToString("yyyy-MM-dd");

            //}
            //int y = Convert.ToInt32(laihanxx.I_Y);
            //int m = Convert.ToInt32(laihanxx.I_M);
            //获取上月实用,超用,加价

            //DataRowCollection rowsL1 = new YS_JH_YONGHUYSSJProcess().SelectYS_JH_YONGHUYSSJsDynamic("I_JLZT=0 AND I_Y=" + (laihanxx.I_TZM == 1 ? laihanxx.I_TZY - 1 : laihanxx.I_TZY) + " AND I_M=" + (laihanxx.I_TZM==1?12:laihanxx.I_TZM-1) + " AND S_YONGHUH='" + laihanxx.S_YONGHUBH + "'", null).Rows;
            //if(rowsL1.Count>0)
            //{
            //    var a=new YS_JH_YONGHUYSSJ();
            //    this.txtCYJE_SY.Text=rowsL1[0]["N_CYJE_SY"].ToString();
            //    this.txtJJJE_SY.Text = rowsL1[0]["N_JJJE_SY"].ToString();
            //    this.txtSYL_SY.Text = rowsL1[0]["I_SYL_SY"].ToString();
            //}
            int? Errcode = 0;
            DataSet jhxx = new SpHelper().P_YS_LH_YUEDUTZJHXXCX(BusinessTool.ZHANDIANBH(), (int)laihanxx.I_TZY, (int)laihanxx.I_TZM, laihanxx.S_YONGHUBH.Trim(), out Errcode);
            if (Errcode < 0)
            {
                throw new Exception("系统数据缺失,请联系技术人员");
            }
            decimal ysj=0;
            if (jhxx != null && jhxx.Tables.Count > 0 && jhxx.Tables[0] != null && jhxx.Tables[0].Rows.Count > 0)
            {
                DataRow dr = jhxx.Tables[0].Rows[0];
                this.txtCYJE_SY.Text = dr["N_CYJE_SY"].ToString();
                this.txtJJJE_SY.Text = dr["N_JJJE_SY"].ToString();
                this.txtSYL_SY.Text = dr["I_SYL_SY"].ToString();

                this.txtYJH.Text = dr["I_YJH"].ToString();
                this.txtJJJH.Text = dr["I_JJJH"].ToString();

                this.txtSYL.Text = dr["I_SYL"].ToString();
                this.txtHGL.Text = dr["I_HGL"].ToString();

                this.txtJJCS.Text = dr["I_JJCS"].ToString();
                this.txtCYJE.Text = dr["N_CYJE"].ToString();
                this.txtCYL.Text = dr["I_CYL"].ToString();
                ysj= Convert.ToDecimal(dr["N_YSJ"].ToString() == "" ? "0" : dr["N_YSJ"].ToString());//20190325 add
                //txtGuBiaoL.Text = dr["V_GuBiaoL"].ToString();               
            }
            //计算调整后加价信息(调整量取最后一个审批量计算)
            DataRowCollection rowsL1 = new YS_LH_YUETIAOZProcess().SelectYS_LH_YUETIAOZsDynamic("I_JLZT=0 AND S_LAIHANBH='"+laihanxx.S_LAIHANBH+"'",null).Rows;
            if(rowsL1.Count>0)
            {
                int tzl=!Convert.IsDBNull(rowsL1[0]["I_CHUZHANG"])?Convert.ToInt32(rowsL1[0]["I_CHUZHANG"]):
                        !Convert.IsDBNull(rowsL1[0]["I_JICAIKZ"])?Convert.ToInt32(rowsL1[0]["I_JICAIKZ"]):
                        !Convert.IsDBNull(rowsL1[0]["I_JIESHUIKZ"])?Convert.ToInt32(rowsL1[0]["I_JIESHUIKZ"]):
                        !Convert.IsDBNull(rowsL1[0]["I_ZHUREN"])?Convert.ToInt32(rowsL1[0]["I_ZHUREN"]):
                        !Convert.IsDBNull(rowsL1[0]["I_YEWUYJY"])?Convert.ToInt32(rowsL1[0]["I_YEWUYJY"]):
                        !Convert.IsDBNull(rowsL1[0]["I_SHENQINGL"]) ? Convert.ToInt32(rowsL1[0]["I_SHENQINGL"]) :
                        0;
                int jjl = Convert.ToInt32(this.txtCYL.Text == "" ? "0" : this.txtCYL.Text) - tzl;
                jjl = jjl < 0 ? 0 : jjl;
                this.txtJJL_tz.Text = jjl.ToString();
                this.txtJJJE_tz.Text = (jjl * ysj * Convert.ToInt32(this.txtJJCS.Text)).ToString();
                //20190325 add 判断为空或者为0时赋值0
                if (this.txtCYJE.Text.Trim() == "" || this.txtCYJE.Text.Trim() == "0")
                {
                    this.txtJJLV_tz.Text = "0";
                }
                else
                {
                    this.txtJJLV_tz.Text = (Convert.ToDecimal(this.txtJJJE_tz.Text) * 100 / Convert.ToDecimal(this.txtCYJE.Text)).ToString("0.00");
                }
            }
            DataTable userdt = new YS_YG_YONGHUXXProcess().SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and I_LEIXING=0 and i_jlzt=0", laihanxx.S_YONGHUBH), "", null);
            if (userdt != null && userdt.Rows.Count > 0)
            {
                txtYongHuM.Text = userdt.Rows[0]["S_YONGHUM"].ToString();
                cFUFEI.Checked = (userdt.Rows[0]["I_CHENNUOFF"].ToString() == "1");
                cTUOSHOU.Checked = (userdt.Rows[0]["I_SHOUFEIFS"].ToString() == "1");

                //DataTable user = BusinessTool.GetTextAndValue("view_as_userinfo", "UserID", "UserName", null, string.Format("UserID={0} ", userdt.Rows[0]["S_YEWUY"])).Tables[0];

                //txtYeWuY.Text = user.Rows[0]["Value"].ToString();
            }
            this.txtYeWuY.Text = laihanxx.S_YWY;
            //获取受理日期等
            DataRow drTemp = new SpHelper().P_YS_LHGETINFODETAIL(laihanxx.S_LAIHANBH, (int)laihanxx.I_LAIHANLX).Tables[0].Rows[0];
            this.txtShouLiRQ.Text = drTemp["D_SHOULIRQ"] == DBNull.Value ? "" : Convert.ToDateTime(drTemp["D_SHOULIRQ"]).ToString("yyyy-MM-dd");
            //this.txtYeWuY.Text = Convert.ToString(drTemp["S_YWY"]);

            // 合计
            DataSet hjxx = sqlHelper.P_YS_LH_YUEDUTZJHHJCX(BusinessTool.ZHANDIANBH(), (int)laihanxx.I_TZY, (int)laihanxx.I_TZM, LoginInfo.CurrentUser.UserID);
            if (hjxx != null && hjxx.Tables.Count > 0 && hjxx.Tables[0] != null && hjxx.Tables[0].Rows.Count > 0)
            {
                DataRow dr = hjxx.Tables[0].Rows[0];
                this.txt_VT_CYJE.Text = dr["VT_CYJE"].ToString();
                this.txt_VT_JJJE.Text = dr["VT_JJJE"].ToString();
                this.txt_VT_JJLV.Text = dr["VT_JJLV"].ToString();
                this.txt_VT_JULV.Text = dr["VT_JULV"].ToString();
                this.txt_VT_CHULV.Text = dr["VT_CHULV"].ToString();
                this.txt_VT_XDLV.Text = dr["VT_XDLV"].ToString();
            }
        }

        public void ClearInfo()
        {
            txtXingZhengXKSLBH.Text = "";
            txtTongYiSPBH.Text = "";

            //txtChaoYongBL.Text = "";
            //txtChaoYongE.Text = "";
            //txtChaoYongL.Text = "";
            //txtGuBiaoL.Text = "";

            //txtHuiGuanL.Text = "";
            //txtJiaJiaJE.Text = "";
            //txtJiaJiaL.Text = "";
            //txtJiaJiaLV.Text = "";
            //txtJiJianL.Text = "";


            //txtYuanJiH.Text = "";

            //txtChaoYongJE.Text = "";
            //txtJiaJiaJEZ.Text = "";
            //txtJiaJiaLVZ.Text = "";

            //txtShangYueCYE.Text = "";
            //txtShangYueJJE.Text = "";
            //txtShiYongL.Text = "";
            //txtShangYueSY.Text = "";

            txtShouLiRQ.Text = "";
            txtYeWuY.Text = "";
            txtYongHuM.Text = "";

           
        }

        
        
        #endregion



        public ValidateRS Validate()
        {
            throw new NotImplementedException();
        }
    }
}